<html>
<head>
    <title>ws_test</title>
</head>
<body>
<script type="text/javascript">
    var sock = null;
    var wsuri = "ws://localhost:8082/sss";


    window.onload = function() {
        console.log("onload");

        sock = new WebSocket(wsuri);
        //建立连接后触发
        sock.onopen = function() {
            console.log(" connected to " + wsuri);
        }
        // 关闭连接时候触发
        sock.onclose = function(e) {
            console.log("connection closed (" + e.code + ")");
        }
        // 收到消息后触发
        sock.onmessage = function(e) {
            console.log("message received: " + e.data);
        }
        //发生错误的时候触发
        sock.onerror=function (e) {
            console.log("error: "+wsuri)
        }
    };

    function send() {
        var msg = document.getElementById('message').value;
        sock.send(msg);
    };
</script>
<h1>GoWebSocketDemo</h1>
<form>
    <p>
        Message: <input id="message" type="text" value="">
    </p>
</form>
<button onclick="send();">send message</button>
</body>
</html>